<template>
  <div v-loading="loading">
    <queryHead v-if="head" :explain="explain" :result="msg" :time="time" :price="price" @query="query"/>
    <div v-if="lock" style="background-color: #fafafa;padding: 5px;border-radius: 5px">
      <table id="fxbg">
        <tr class="fxbg_border_none">
          <td colspan="60" style="text-align: left">
            <div style="text-align: right">
              <el-button @click="downLoadPDF()" type="primary">下载报告</el-button>
            </div>
            <i class="el-icon-s-check">
              <label>身份信息核验：</label>
            </i>
          </td>
        </tr>
        <tr class="fxbg_titles">
          <td colspan="20">实名认证</td>
          <td colspan="40">运营商手机三要素</td>
        </tr>
        <tr>
          <td colspan="20" rowspan="3">姓名与身份证号
            <label>
              {{ jbxx.smrz.final_valid_result == '0' ? '一致' : '不一致' }}
            </label>
          </td>
          <td colspan="10">服务商</td>
          <td colspan="10">服务商代码</td>
          <td colspan="10">归属省份</td>
          <td colspan="10">归属城市</td>
        </tr>
        <tr>
          <td colspan="10">{{ jbxx.sjsys.attribute }}</td>
          <td colspan="10">{{ jbxx.sjsys.attribute_en }}</td>
          <td colspan="10">{{ jbxx.sjsys.province }}</td>
          <td colspan="10">{{ jbxx.sjsys.city }}</td>
        </tr>
        <tr>
          <td colspan="40">
            <label>
              {{
                jbxx.sjsys.checkResult == '0' ? '手机号与身份证号，姓名一致' : jbxx.sjsys.checkResult == '1' ? '手机号与身份证号或姓名不一致' : ''
              }}
            </label>
          </td>
        </tr>
        <tr class="fxbg_border_none">
          <td colspan="60" style="text-align: left">
            <i class="el-icon-s-check">
              <label>学历信息：</label>
            </i>
          </td>
        </tr>
        <tr>
        <tr class="fxbg_titles">
          <td colspan="6">ID</td>
          <td colspan="9">专业名称</td>
          <td colspan="9">学历</td>
          <td colspan="9">学校类型
            <span style="font-size: 8px;display: block">(985、211、双一流、其他)</span>
          </td>
          <td colspan="9">入学时间</td>
          <td colspan="9">毕业时间</td>
          <td colspan="9">学习形式</td>
        </tr>
        <tr v-for="(item,index) of xl">
          <td colspan="6">{{ 'EDU.' + index + 1 }}</td>
          <td colspan="9">{{ item.zymc }}</td>
          <td colspan="9">{{ item.xl }}</td>
          <td colspan="9">{{ item.xxlx }}</td>
          <td colspan="9">{{ item.ksrq }}</td>
          <td colspan="9">{{ item.jsrq }}</td>
          <td colspan="9">{{ item.xxxs }}</td>
        </tr>
        <tr v-if="xl.length==0">
          <td colspan="60">{{ xlMsg }}</td>
        </tr>

        <tr class="fxbg_border_none">
          <td colspan="60" style="text-align: left">
            <i class="el-icon-s-check">
              <label>不良行为核验：</label>
            </i>
          </td>
        </tr>
        <tr class="fxbg_titles">
          <td colspan="8">前科</td>
          <td colspan="8">涉毒</td>
          <td colspan="8">吸毒</td>
          <td colspan="8">其它</td>
          <td colspan="7">经济类前科</td>
          <td colspan="12">侵犯公民人身，民主权利</td>
          <td colspan="9">扰乱公共秩序罪</td>
        </tr>
        <tr>
          <td colspan="8">
            {{ blxw == 'A' || blxw == 'J' || blxw == 'N' || blxw == 'R' ? '有命中' : '良好无记录' }}
          </td>
          <td colspan="8">{{ blxw == 'B' ? '有命中' : '良好无记录' }}</td>
          <td colspan="8">{{ blxw == 'C' ? '有命中' : '良好无记录' }}</td>
          <td colspan="8">{{ blxw == 'F' ? '有命中' : '良好无记录' }}</td>
          <td colspan="7">{{ blxw == 'J' ? '有命中' : '良好无记录' }}</td>
          <td colspan="12">{{ blxw == 'N' ? '有命中' : '良好无记录' }}</td>
          <td colspan="9">{{ blxw == 'R' ? '有命中' : '良好无记录' }}</td>
        </tr>

        <tr class="fxbg_border_none">
          <td colspan="60" style="text-align: left">
            <i class="el-icon-s-check">
              <label>工商关联：</label>
            </i>
          </td>
        </tr>

        <tr>
          <td colspan="60" v-if="gsgl.length == 0">
            {{ gsglMessge }}
          </td>
        </tr>
        <template v-for="(item,index ) of gsgl">
          <tr class="fxbg_titles">
            <td colspan="60">
              {{ item.pName }} —————— {{ item.orgName }}
            </td>
          </tr>
          <tr>
            <td colspan="10">
              <div class="gsglbt">1. 关联</div>
            </td>
            <td colspan="50" style="font-size: 12px;color: #606266">{{ relationship(item.relationship) }}</td>
          </tr>

          <tr>
            <td colspan="10" rowspan="2">
              <div class="gsglbt">2. 公司基本信息</div>
            </td>
            <td colspan="50">
              <el-descriptions v-if="item.basicInfo" size="mini" :column="4">
                <el-descriptions-item label="企业名">
                  {{ item.basicInfo.name ? item.basicInfo.name : '' }}
                </el-descriptions-item>
                <el-descriptions-item label="企业类型">
                  {{ item.basicInfo.companyOrgType ? item.basicInfo.companyOrgType : '' }}
                </el-descriptions-item>

                <el-descriptions-item label="统一社会信用代码">
                  {{ item.basicInfo.creditCode ? item.basicInfo.creditCode : '' }}
                </el-descriptions-item>
                <el-descriptions-item label="注册号">
                  {{ item.basicInfo.regNumber ? item.basicInfo.regNumber : '' }}
                </el-descriptions-item>
                <el-descriptions-item label="省份简称">
                  {{ item.basicInfo.base ? item.basicInfo.base : '' }}
                </el-descriptions-item>
                <el-descriptions-item label="企业状态">
                  {{ item.basicInfo.regStatus ? item.basicInfo.regStatus : '' }}
                </el-descriptions-item>
                <el-descriptions-item label="行业">
                  {{ item.basicInfo.industry ? item.basicInfo.industry : '' }}
                </el-descriptions-item>
                <el-descriptions-item label="成立日期">
                  {{ item.basicInfo.estiblishTime ? item.basicInfo.estiblishTime : '' }}
                </el-descriptions-item>

                <el-descriptions-item label="注册资本">
                  {{ item.basicInfo.regCapital ? item.basicInfo.regCapital : '' }}
                </el-descriptions-item>
                <el-descriptions-item label="注册资本币种">
                  {{ item.basicInfo.regCapitalCurrency ? item.basicInfo.regCapitalCurrency : '' }}
                </el-descriptions-item>

                <el-descriptions-item label="法人类型">
                  {{ item.basicInfo.type ? item.basicInfo.type : '' }}
                </el-descriptions-item>

                <el-descriptions-item label="法人姓名">
                  {{ item.basicInfo.legalPersonName ? item.basicInfo.legalPersonName : '' }}
                </el-descriptions-item>
              </el-descriptions>

            </td>
          </tr>

          <tr>
            <td colspan="50" style="font-size: 12px;color: #606266">
              主要人员：{{ item.basicInfo.staffList ? staffList(item.basicInfo.staffList) : '' }}
            </td>
          </tr>

          <tr>
            <td colspan="10">
              <div class="gsglbt">3. 查询人持股</div>
            </td>
            <td colspan="50">
              <el-descriptions v-if="item.stockholder" size="mini" :column="5">
                <el-descriptions-item label="股东类型">
                  {{ item.stockholder.orgHolderType ? item.stockholder.orgHolderType : '' }}
                </el-descriptions-item>
                <el-descriptions-item label="出资时间">
                  {{ item.stockholder.investDate ? item.stockholder.investDate : '' }}
                </el-descriptions-item>
                <el-descriptions-item label="占比">
                  {{ item.stockholder.investRate ? item.stockholder.investRate : '' }}
                </el-descriptions-item>
                <el-descriptions-item label="出资金额">
                  {{ item.stockholder.subscriptAmt ? item.stockholder.subscriptAmt : '' }}
                </el-descriptions-item>
                <el-descriptions-item label="股东名">
                  {{ item.stockholder.orgHolderName ? item.stockholder.orgHolderName : '' }}
                </el-descriptions-item>
              </el-descriptions>
            </td>
          </tr>

          <tr>
            <td colspan="10">
              <div class="gsglbt">4. 行政处罚</div>
            </td>
            <td colspan="50">
              <el-descriptions v-if="item.adminPenalty" v-for="(itmm,index) of item.adminPenalty"
                               :title="'Num.'+index+1" size="mini" :column="4">
                <el-descriptions-item label="处罚单位">
                  {{ item.departmentName ? item.departmentName : '' }}
                </el-descriptions-item>
                <el-descriptions-item label="处罚事由/违法行为类型">
                  {{ item.reason ? item.reason : '' }}
                </el-descriptions-item>
                <el-descriptions-item label="决定文书号">
                  {{ item.punishNumber ? item.punishNumber : '' }}
                </el-descriptions-item>
                <el-descriptions-item label="处罚类别">
                  {{ item.type ? item.type : '' }}
                </el-descriptions-item>
                <el-descriptions-item label="处罚结果/内容">
                  {{ item.content ? item.content : '' }}
                </el-descriptions-item>
                <el-descriptions-item label="处罚日期">
                  {{ item.decisionDate ? item.decisionDate : '' }}
                </el-descriptions-item>
                <el-descriptions-item label="法定代表人">
                  {{ item.legalPersonName ? item.legalPersonName : '' }}
                </el-descriptions-item>
              </el-descriptions>
            </td>
          </tr>
          <tr>
            <td colspan="10">
              <div class="gsglbt">5. 被执行人员</div>
            </td>
            <td colspan="50">
              <el-descriptions v-if="item.executedPerson" v-for="(itmm,index) of item.executedPerson"
                               :title="'Num.'+index+1" size="mini" :column="5">
                <el-descriptions-item label="案号">
                  {{ item.caseCode ? item.caseCode : '' }}
                </el-descriptions-item>
                <el-descriptions-item label="被执行人名称">
                  {{ item.pname ? item.pname : '' }}
                </el-descriptions-item>
                <el-descriptions-item label="立案日期">
                  {{ item.caseCreateTime ? item.caseCreateTime : '' }}
                </el-descriptions-item>
                <el-descriptions-item label="执行法院">
                  {{ item.execCourtNam ? item.execCourtNam : '' }}
                </el-descriptions-item>
                <el-descriptions-item label="执行标的（元）">
                  {{ item.execMoney ? item.execMoney : '' }}
                </el-descriptions-item>
              </el-descriptions>
            </td>
          </tr>
          <tr>
            <td colspan="10">
              <div class="gsglbt">6. 失信被执行人员</div>
            </td>
            <td colspan="50">
              <el-descriptions v-if="item.dishonestExecutedPerson" v-for="(itmm,index) of item.dishonestExecutedPerson"
                               :title="'Num.'+index+1" size="mini" :column="5">
                <el-descriptions-item label="案号">
                  {{ item.casecode ? item.casecode : '' }}
                </el-descriptions-item>
                <el-descriptions-item label="法人、负责人姓名">
                  {{ item.businessentity ? item.businessentity : '' }}
                </el-descriptions-item>
                <el-descriptions-item label="省份地区">
                  {{ item.areaname ? item.areaname : '' }}
                </el-descriptions-item>
                <el-descriptions-item label="法院">
                  {{ item.courtname ? item.courtname : '' }}
                </el-descriptions-item>
                <el-descriptions-item label="未履行部分">
                  {{ item.unperformPart ? item.unperformPart : '' }}
                </el-descriptions-item>
                <el-descriptions-item label="已履行部分">
                  {{ item.performedPart ? item.performedPart : '' }}
                </el-descriptions-item>
                <el-descriptions-item label="失信人类型">
                  {{ item.type ? item.type == 0 ? "代表人" : item.type == 1 ? "代表公司" : '' : '' }}
                </el-descriptions-item>
                <el-descriptions-item label="失信人名称">
                  {{ item.iname ? item.iname : '' }}
                </el-descriptions-item>
                <el-descriptions-item label="失信被执行人行为具体情形">
                  {{ item.disrupttypename ? item.disrupttypename : '' }}
                </el-descriptions-item>
                <el-descriptions-item label="身份证号/组织机构代码">
                  {{ item.cardnum ? item.cardnum : '' }}
                </el-descriptions-item>
                <el-descriptions-item label="履行情况">
                  {{ item.performance ? item.performance : '' }}
                </el-descriptions-item>
                <el-descriptions-item label="立案时间">
                  {{ item.regdate ? item.regdate : '' }}
                </el-descriptions-item>
                <el-descriptions-item label="生效法律文书确定的义务">
                  {{ item.duty ? item.duty : '' }}
                </el-descriptions-item>
                <el-descriptions-item label="做出执行的依据单位">
                  {{ item.gistunit ? item.gistunit : '' }}
                </el-descriptions-item>

                <el-descriptions-item label="执行依据文号">
                  {{ item.gistid ? item.gistid : '' }}
                </el-descriptions-item>
              </el-descriptions>
            </td>
          </tr>
        </template>


        <tr class="fxbg_border_none">
          <td colspan="60" style="text-align: left">
            <i class="el-icon-s-check">
              <label>法院涉案风险信息：</label>
            </i>
          </td>
        </tr>
        <tr class="fxbg_titles">
          <td colspan="11">案号</td>
          <td colspan="6">案件类型</td>
          <td colspan="9">法院</td>
          <td colspan="4">诉讼身份</td>
          <td colspan="6">立案时间</td>
          <td colspan="6">案件状态</td>
          <td colspan="6">案由</td>
          <td colspan="6">结案方式</td>
          <td colspan="6">涉案总额</td>

        </tr>
        <template v-for="(objValue,key,index) of fyxx" v-if="contain(key,objValue)">
          <tr v-for="(cases,i) in objValue.cases">
            <td colspan="11">{{ cases.c_ah }}</td>
            <td colspan="6">{{ include(key) }}</td>
            <td colspan="9">{{ cases.n_jbfy }}</td>
            <td colspan="4">{{ cases.n_ssdw }}</td>
            <td colspan="6">{{ cases.d_larq }}</td>
            <td colspan="6">{{ cases.n_ajlx }}</td>
            <td colspan="6">{{ cases.n_laay }}</td>
            <td colspan="6">{{ cases.n_jafs }}</td>
            <td colspan="6">{{ cases.n_sqzxbdje }}</td>
          </tr>
        </template>
        <tr v-if="fyxx.length == 0 || !isXr">
          <td colspan="60">
            {{ fyxxMessge }}
          </td>
        </tr>
        <tr class="fxbg_border_none">
          <td v-for="n of 60"/>
        </tr>
      </table>
    </div>
    <h3 style="text-align: center" v-if="sjsysMsg">{{ sjsysMsg }}</h3>
  </div>
</template>
<script>
  import queryHead from "@/views/components/queryHead.vue";
  import {queryRecord, queryData, reportFee} from "@/api/system/query";
  import {downloadPDF} from "@/utils/htmlToPdf.js";

  export default {
    components: {queryHead},
    name: "rzbd",
    props: {
      queryData: {
        required: true,
        type: Object
      },
      price: {
        default: null,
        type: Number
      },
      priceType: {
        default: null,
        type: Boolean
      },
      explain: {
        default: null,
        type: String
      },
      head: {
        default: true,
        type: Boolean
      }
    },
    data() {
      return {
        loading: false,
        lock: false,

        msg: undefined,
        time: undefined,

        isXr: false,
        sjsysMsg: null,
        jbxx: {
          smrz: {
            final_valid_result: ''
          },
          sjsys: {
            attribute: '',
            attribute_en: '',
            checkResult: '',
            city: '',
            province: ''
          }
        },
        blxw: '',

        fyxx: {},
        fyxxMessge: null,
        smrzMsg: null,

        xl: [],
        xlMsg: null,
        gsgl: [],
        gsglMessge: null
      }
    },
    created() {
      this.loading = true;
      queryRecord(this.queryData).then(response => {
        console.log('---rzbg--response-', response)
        if (response.code == 200){
          this.loading = false
          return
        }
        this.disResponse(response)
      })
    },

    methods: {
      query() {
        this.loading = true
        queryData(this.queryData).then(response => {

          console.log('---rzbg--response-', response)

          this.disResponse(response)
        });
      },
      disResponse(response) {
        this.time = response.time
        if (response.info) {
          try{
            let info = JSON.parse(response.info)
            console.log('---rzbg---', info)
            let smrzRes = info.smrz
            if (smrzRes.retcode == '000000' && smrzRes.retdata) {
              this.jbxx.smrz.final_valid_result = smrzRes.retdata.final_valid_result
            } else {
              // this.smrzMsg = smrzRes.retmsg
              this.$modal.msgWarning('实名认证查询失败，原因：' + smrzRes.retmsg);
            }

            let sjsysRes = info.sjsys
            if (sjsysRes.retcode == '000000') {
              this.jbxx.sjsys = sjsysRes.retdata
            } else {
              this.$modal.msgWarning('手机三要素查询失败，原因：' + sjsysRes.retmsg);
              this.sjsysMsg = sjsysRes.retmsg
              return
            }

            let blxw = info.blxw
            if (blxw.retcode == '000000') {
              this.blxw = blxw.retdata.level
            }

            let sf = info.sf
            if (sf.retcode == '000000') {
              const retdata = sf.retdata
              this.fyxxMessge = retdata.messge
              if (retdata.resultCode == 1) {
                // 法院风险信息
                const detail0 = retdata.detail[0]
                this.fyxx = detail0
              }
            }

            let xl = info.xl
            this.xlMsg = xl.msg
            if (xl.code == 200 && xl.data) {
              this.xlMsg = xl.data.messge
              if (xl.data.detail) {
                this.xl = xl.data.detail
              }
            }

            let gsgl = info.gsgl
            this.gsglMessge = gsgl.msg
            if (gsgl.code == 200 && gsgl.data) {
              this.gsglMessge = gsgl.data.messge
              if (gsgl.data.detail) {
                this.gsgl = gsgl.data.detail
              }
            }
            this.msg = "查询完成"
            this.lock = true

          }catch (e){
            console.error(e)
          }finally {
            this.loading = false
          }
        }

      },
      relationship(arr = []) {
        let rel = {
          lp: '法人',
          sh: '股东',
          tm: '高管'
        }
        let ss = '';
        arr.forEach(i => {
          ss += ('  ' + rel[i])
        })
        return ss
      },
      staffList(sf) {
        let str = ''
        if (sf.result) {
          let result = sf.result

          result.forEach(i => {
            str += i.name;
            if (i.typeJoin) {
              str += '（'
              i.typeJoin.forEach(j => {
                str += (j + ' ')
              })
              str += '）'
            }
          })
        }
        return str
      },
      include(item) {
        let index = ['civil', 'criminal', 'administrative', 'implement', 'bankrupt', 'preservation'].indexOf(item)
        return ["民事案件", "刑事案件", "行政案件", "执行案件", "破产清算", "非诉讼保全审查"][index]
      },
      contain(item, obj) {
        let ss = false
        if (['civil', 'criminal', 'administrative', 'implement', 'bankrupt', 'preservation'].indexOf(item) != -1 && 'cases' in obj) {
          ss = true
          this.isXr = true
        }
        return ss
      },
      downLoadPDF() {
        reportFee({
          productId: 17,
          queryId: this.queryData.queryId,
        }).then(response => {
          if (response.code == 200) {
            downloadPDF(document.getElementById('fxbg'), '天启入职背调报告' + this.queryData.queryId + '.pdf')
          } else {
            this.$modal.msgWarning(response.msg);
          }
          this.show = true;
        });
      }
    }
  };
</script>
<style scoped>

  #fxbg {
    margin: 0 auto;
    width: 95%;
    padding: 0 100px;
    table-layout: fixed;
    border-collapse: collapse;
  }

  #fxbg td {
    border: 1px solid #000000;
    text-align: center;
    width: 1.64%;
    padding: 10px 0px;
  }

  .fxbg_titles {
    background-color: #f3f4f8;
  }

  #fxbg .fxbg_border_none td {
    border: none;
  }

  .gsglbt {
    margin-left: 20px;
    text-align: left;
  }
</style>
